package com.yuantu.judiciary.dao;

import com.yuantu.judiciary.model.domain.DiscountCodeDO;
import com.yuantu.judiciary.model.domain.OrganizationSourceDO;
import com.yuantu.judiciary.model.form.DiscountCodeForm;
import com.yuantu.judiciary.model.form.DiscountCodeStatusForm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 动态信息
 *
 * @author syw
 * @since 2023-08-21
 **/
public interface IOrganizationSourceDao extends JpaRepository<OrganizationSourceDO, Long> {


    OrganizationSourceDO findInfoByIdAndDeletedFalse(Long id);

    @Query("select os from OrganizationSourceDO os where os.deleted = false and os.id != 1 " +
            "and (:orgSource is null or :orgSource = '' or os.orgSource like concat('%', :orgSource, '%')) ")
    Page<OrganizationSourceDO> findInfosByOrgSource(String orgSource, Pageable pageable);

    @Query("select os from OrganizationSourceDO os where os.deleted = false ")
    List<OrganizationSourceDO> findAllInfos();

    @Modifying
    @Query("update OrganizationSourceDO set deleted = true where id = :orgSourceId and deleted = false ")
    void removeInfoById(Long orgSourceId);
}
